var grid;
define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {
    $(function () {
        //每列数据列性
        var columns = [
            {
                title: '用户名',
                dataIndex: 'user_id',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].name + "</span>";
                }
            },
            {
                title: '手机号',
                dataIndex: 'mobile',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].mobile + "</span>";
                }
            },
            {
                title: '头像',
                dataIndex: 'headImage',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><img src='" + data[datarow].headImage + "' width='80px;' height='80px;'></span>";
                }
            },
            {
                title: '注册时间',
                dataIndex: 'create_date',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].create_date + "</span>";
                }
            },
            {
                title: '激活码',
                dataIndex: 'invitation_code',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].invitation_code + "</span>";
                }
            },

        ];

        //{
        //    title: '操作',
        //        dataIndex: 'action',
        //    dataSource: function (data, datarow, gridobj, current_column) {
        //    return "<span>&nbsp;<a href='javascript:void(0)' style='color: dodgerblue;' class='unfreeze' unfreeze_id = '"+data[datarow].user_id+"'>查看详情</a></span>";
        //}
        //},

        //数组初始化

        function dataInit() {
            grid = new Grid("/pte/api/user", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {
            var name=$("#name").val();
            var param="name=" + name;
            return param;
        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });
    ////封号
    //$(document).on("click",".freeze",function(){
    //    var act_id=$(this).attr("freeze_id");
    //    if(act_id){
    //        console.log('wtf');
    //
    //        bootbox.confirm("是否要封号？",function(result){
    //            if(result) {
    //                console.log('wtf');
    //                IO.get("act/user_freeze",{act_id:act_id},function(d){
    //                    bootbox.alert(d.msg,function(){
    //                        if (d.code == 0) {
    //                            location.href = '/pte/user';
    //                        }
    //                    })
    //                });
    //            }
    //        });
    //    }
    //});
    //解封
    //$(document).on("click",".unfreeze",function(){
    //    var act_id=$(this).attr("unfreeze_id");
    //    if(act_id){
    //        console.log('wtf');
    //
    //        bootbox.confirm("是否要解封？",function(result){
    //            if(result) {
    //                IO.get("act/user_unfreeze",{act_id:act_id},function(d){
    //                    bootbox.alert(d.msg,function(){
    //                        if (d.code == 0) {
    //                            location.href = '/pte/user';
    //                        }
    //                    })
    //                });
    //            }
    //        });
    //    }
    //});

});

